import 'package:word_game/battle/battle.dart';
import 'package:word_game/battle/monster_manager.dart';
import 'package:word_game/engine/core.dart';
import 'package:word_game/engine/eventable_manager.dart';
import 'package:word_game/engine/npc.dart';
import 'package:word_game/engine/npc_manager.dart';
import 'package:word_game/engine/scene_manager.dart';
import 'sightable.dart';

class Scene extends Sightable {
  Scene(Map map) : super('') {
    code = map['code'];
    name = map['name'];
    var npcs = map['npcs'] ?? [];
    for (var item in npcs) {
      NPC obj = NPC({});
      if (item is String) {
        obj = NPCManager.instance.objectWithID(item);
      } else if (item is Map) {
        obj = NPC(item);
      }
      add(obj);
    }
    var scenes = map['scenes']??[];
    for (var item in scenes) {
      Scene obj = Scene({});
      if (item is String) {
        obj = SceneManager.instance.objectWithCode(item);
      } else if (item is Map) {
        obj = Scene(item);
      }
      add(obj);
    }
    var monsters = map['monsters'] ?? [];
    for (var item in monsters) {
      Monster obj = Monster({});
      if (item is String) {
        obj = MonsterManager.instance.objectWithCode(item);
      } else if (item is Map) {
        obj = Monster(item);
      }
      add(obj);
    }
    var events = map['events'] ?? [];
    for (var item in events) {
      Eventable obj = Eventable('');
      if (item is String) {
        obj = EventableManager.instance.objectWithCode(item);
      } else if (item is Map) {
        obj = Eventable(item['name']);
      }
      add(obj);
    }
    var materials = map['materials'] ?? [];
    for (var item in materials) {
      Thing obj = Thing(null);
      if (item is String) {
        obj = MaterialManager.instance.newMaterialWithCode(item);
      } else if (item is Map) {
        obj = Thing(item);
      }
      add(obj);
    }
  }
}